package com.zjitc.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zjitc.dao.CountryDao;
import com.zjitc.pojo.Country;
import com.zjitc.service.CountryService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/26 15:04
 * @description:
 */
@Service
public class CountryServiceImp implements CountryService {

  @Autowired
  private CountryDao dao;

  @Override
  public List<Country> findAllCountry() {
    return dao.findAll();
  }

  @Override
  public List<Country> findCountries(Integer start,Integer count) {
    PageHelper.startPage(start,count);
    List<Country> countries = dao.findAll();
    return countries;
  }

  @Override
  public List<Country> searchCountry(String region) {
    PageHelper.startPage(1,10);
    region = "%" + region + "%";
    List<Country> countries = dao.searchCountry(region);
    return countries;
  }

  @Override
  public void add(Country country) {
    dao.add(country);
  }

  @Override
  public Country findbycode(String code) {
    Country findbycode = dao.findbycode(code);
    return findbycode;
  }

  @Override
  public int update(Country country) {
   return  dao.update(country);
  }

  @Override
  public int delete(String code) {
    return dao.delete(code);
  }

  @Override
  public List<Country> searchfind(Integer start, Integer count, String region) {
    PageHelper.startPage(start,count);
    region = "%" + region + "%";
    List<Country> countries = dao.searchCountry(region);
    return countries;
  }
}
